
 /**
 * SystemManageTreeMenu.java.java.
 * User: BrianChen Date: 2012-7-31 下午04:46:09
 *
 * Copyright (c) 2009 Hewlett-Packard Development Company, L.P.
 * All rights reserved.
 */
package com.collapsar.snail.menu.form;

import java.util.List;

import com.collapsar.core.menu.TreeNode;
import com.collapsar.core.security.model.Authority;
import com.collapsar.snail.menu.util.MenuConstants;

/**
 * <pre>
 * REVISIONS: 
 * Version 	Date 		Author 			Description
 * ------------------------------------------------------------------- 
 * 1.0 		2012-7-31 	BrianChen 	1. Created this class. 
 * </pre>
 * 
 * @author BrianChen
 * @date 2012-7-31 下午04:46:09
 * @version 1.0
 * @see
 * 
 */
public class SystemManageTreeMenu extends TreeNode{
	private static SystemManageTreeMenu theInstance = new SystemManageTreeMenu(MenuConstants.MID_SYS, "系统管理");
	private SystemManageTreeMenu(String id, String name){
		super(id, name);
	}

//	public static synchronized SystemManageTreeMenu getInstance(){
//		if(theInstance == null){
//			theInstance = new SystemManageTreeMenu(MenuConstants.MID_SYS, "系统管理");
////			for(Map.Entry ent : MenuConstants.MID_MAP_SYS.entrySet()){
////				TreeNode node = new TreeNode(ent.getKey().toString(), ent.getValue().toString());
////				theInstance.getChildren().add(node);
////			}
//		}
//		return theInstance;
//	}
	
	public static SystemManageTreeMenu init(List<Authority> authorities){
		TreeNode userMng = null;
		TreeNode groupMng = null;
		TreeNode authMng = null;
		TreeNode logMng = null;
		userMng = new TreeNode(MenuConstants.MID_SYS_USER, "人员管理");
		groupMng = new TreeNode(MenuConstants.MID_SYS_GROUP, "用户组管理");
		authMng = new TreeNode(MenuConstants.MID_SYS_AUTH, "权限管理");
		logMng = new TreeNode(MenuConstants.MID_SYS_LOG, "系统日志管理");
		/*for(Authority auth : authorities){
			if(auth.getCode().startsWith(MenuConstants.MID_SYS_USER)){
				if(userMng == null){
					userMng = new TreeNode(MenuConstants.MID_SYS_USER, "人员管理");
				}
				userMng.getChildren().add(new TreeNode(auth));
			}
			if(auth.getCode().startsWith(MenuConstants.MID_SYS_GROUP)){
				if(groupMng == null){
					groupMng = new TreeNode(MenuConstants.MID_SYS_GROUP, "用户组管理");
				}
				groupMng.getChildren().add(new TreeNode(auth));
			}
			if(auth.getCode().startsWith(MenuConstants.MID_SYS_AUTH)){
				if(authMng == null){
					authMng = new TreeNode(MenuConstants.MID_SYS_AUTH, "权限管理");
				}
				authMng.getChildren().add(new TreeNode(auth));
			}
			if(auth.getCode().startsWith(MenuConstants.MID_SYS_LOG)){
				if(logMng == null){
					logMng = new TreeNode(MenuConstants.MID_SYS_LOG, "系统日志管理");
				}
				logMng.getChildren().add(new TreeNode(auth));
			}
		}*/
		if(!theInstance.getChildren().isEmpty()){
			theInstance.getChildren().clear();
		}
		if(userMng != null){
			theInstance.getChildren().add(userMng);
		}
		if(groupMng != null){
			theInstance.getChildren().add(groupMng);
		}
		if(authMng != null){
			theInstance.getChildren().add(authMng);
		}
		if(logMng != null){
			theInstance.getChildren().add(logMng);
		}
		
		return theInstance;
	}
	
}

